package org.jeecg.modules.appuser.api.person;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.Date.DateUtil;
import org.jeecg.modules.appuser.constant.PayTypeConstant;
import org.jeecg.modules.appuser.constant.TaskNamesConstant;
import org.jeecg.modules.appuser.entity.TbIntegralExchangeConfig;
import org.jeecg.modules.appuser.entity.TbUserIntegral;
import org.jeecg.modules.appuser.entity.TbUserIntegralConfigDetail;
import org.jeecg.modules.appuser.entity.TbUserIntegralDetail;
import org.jeecg.modules.appuser.service.ITbIntegralExchangeConfigService;
import org.jeecg.modules.appuser.service.ITbUserIntegralConfigDetailService;
import org.jeecg.modules.appuser.service.ITbUserIntegralDetailService;
import org.jeecg.modules.appuser.service.ITbUserIntegralService;
import org.jeecg.modules.mall.service.ITbMnUserService;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "app个人中心接口")
@RestController
@RequestMapping("/app/person/api")
public class IntegralTaskController {


    @Autowired
    private ITbUserIntegralService tbUserIntegralService;

    @Autowired
    private ITbIntegralExchangeConfigService tbIntegralExchangeConfigService;


    @ApiOperation("每日任务")
    @GetMapping(value = "/everyDayTask")
    public synchronized Result<?> integralTask(@RequestParam(name = "user_id", required = true) String user_id,
                                  @RequestParam(name = "taskName", required = true) String taskName) throws Exception {

        Map<String, Object> resultData1 = tbUserIntegralService.doActionTask(user_id, taskName);


        return Result.ok(resultData1);
    }

    @ApiOperation("积分兑换配置")
    @GetMapping(value = "/integralExchangeConfig")
    public Result<?> integralExchangeConfig() {

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("sort");
        List<TbIntegralExchangeConfig> tbIntegralExchangeConfigList = tbIntegralExchangeConfigService.list();
        return Result.ok(tbIntegralExchangeConfigList);
    }

    @ApiOperation("积分升级代理")
    @PostMapping(value = "/integralUpgradeAgent")
    public Result<?> integralUpgradeAgent(String user_id) {

        return Result.ok(tbUserIntegralService.integralUpgradeAgent(user_id));
    }

}
